package com.example.demo;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.demo.entity.Category;
import com.example.demo.entity.User;
import com.example.demo.model.DemoData;
import com.example.demo.service.impl.CategoryServiceImpl;
import com.example.demo.service.impl.UserServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@RestController
@MapperScan("com.example.demo")
public class DemoApplication {

	@Autowired
	private CategoryServiceImpl categoryService;
	@GetMapping("/get_categorylist")
	@DS("sjy")
	public List<Category> getCategoryList() {
		return categoryService.list();
	}

	@Autowired
	private UserServiceImpl userService;
	@GetMapping("/get_userlist")
	public List<User> getUserList() {
		return userService.list();
	}

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@GetMapping("/")
	public String home()
	{
		return "Hello world!";
	}

	@GetMapping("/get")
	public DemoData getData() {
		DemoData data = new DemoData();
		data.setId("1");
		data.setName("SpringBoot");
		return data;
	}
}
